package com.frank;

import com.frank.entity.RainBow;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @Author: huweifeng
 * @Date: 2022/11/27
 * @Description: ImportBeanDefinition
 **/
public class MyImportBeanDefinition implements ImportBeanDefinitionRegistrar {
//    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator) {
        boolean b1 = registry.containsBeanDefinition("com.frank.entity.Blue");
        boolean b2 = registry.containsBeanDefinition("com.frank.entity.Red");
        if (b1 && b2) {
            RootBeanDefinition beanDefinition = new RootBeanDefinition(RainBow.class);
            // 把所有需要添加到容器中的bean，调用RootBeanDefinition.registerBeanDefinition手动注册进来
            registry.registerBeanDefinition("rainbow",beanDefinition);
        }
    }

    @Override
    public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry beanDefinitionRegistry) {

    }
}
